<template>
	<div class="help-doc">
		<div>
			<label>{{$t('route.DeviceManager')}}</label>
			<div></div>
			<button><img /><label>{{$t('route.Help_dpcument')}}</label></button>
		</div>

		<div>
			<div>
				<div class="div-handle-right">
					<el-button @click='jumpPage(0)'>{{$t('route.Add')}}</el-button>
					<el-button @click="searchClick">{{$t('route.search')}}</el-button>
					<input v-model="query.search" placeholder="" />
				</div>
			</div>

			<el-table class="table" :data="instructionList" style="width: 100%">
				<el-table-column prop="title" :label="$t('route.title')" />
				<el-table-column prop="detail" :label="$t('route.Details')" width="400" />
				<el-table-column prop="deviceCategory" :label="$t('route.Equipment_category')" />
				<el-table-column prop="typeNum" :label="$t('route.Equipment_model')" />
				<el-table-column prop="nickname" :label="$t('route.Publisher')" />
				<el-table-column :label="$t('route.Type_of_document')">
					<template #default="scope">
						{{formatInsTypeName(scope.row.type)}}
					</template>
				</el-table-column>
				<el-table-column :label="$t('route.File_Type')">
					<template #default="scope">
						{{formatInsSuffixName(scope.row.suffix)}}
					</template>
				</el-table-column>
				<el-table-column align="nickname" label="$t('route.operate')">
					<template #default="scope">
						<el-image v-if='scope.row.suffix==0' style="width: 100px; height: 100px"
							:src="JSON.parse(scope.row.url)[0]" :preview-src-list="JSON.parse(scope.row.url)">
						</el-image>
						<el-button v-if='scope.row.suffix==2' type="text" icon="el-icon-edit"
							@click="pdfDetailClick(scope.row)">{{$t('route.PDFView')}}</el-button>
						<el-button v-if='scope.row.suffix==1' type="text" icon="el-icon-edit"
							@click="videoDetailClick(scope.row)">{{$t('route.Video_viewing')}}</el-button>
					</template>
				</el-table-column>
			</el-table>
			<div class="pagination">
				<el-pagination style="float: right;" background @current-change="handlePageChange" :current-page="query.pageNum"
					:page-size="query.pageSize" layout="total, prev, pager, next" :total="query.total"></el-pagination>
			</div>

		</div>

	</div>
</template>


<script>
	import http from "../../js/http/http.js";
	import api from "../../js/http/api.js";
	import CommonUtils from "../../js/common/common-utils.js";
	import i18n from '../../i18n/index';
	export default {
		data() {
			return {
				instructionList: [],
				query: {
					search: null,
					deviceCategory: i18n.global.t('route.All'),
					typeNum: i18n.global.t('route.All'),
					pageNum: 1,
					pageSize: 10,
					total: 0
				},
			};
		},
		created() {
			this.getInstruction();
		},
		methods: {
			jumpPage() {
				this.$router.push('/admin/add-help-doc')
			},

			formatInsTypeName(type) { //0:使用文档 1:零件手册 2:常见错误 3:安装教程
				if (type == 0) {
					return i18n.global.t('route.Working_with_documents');
				} else if (type == 1) {
					return i18n.global.t('route.Parts_Manual');
				} else if (type == 2) {
					return i18n.global.t('route.Common_errors');
				} else if (type == 3) {
					return i18n.global.t('route.Installation_Tutorial');
				}
				return i18n.global.t('route.Parts_Manual');
			},
			formatInsSuffixName(type) { //0:图片 1:视频 2:PDF
				if (type == 0) {
					return i18n.global.t('route.Picture');
				} else if (type == 1) {
					return i18n.global.t('route.video');
				} else if (type == 2) {
					return i18n.global.t('route.PDF');
				}
				return i18n.global.t('route.video');
			},
			getInstruction() {
				http.post(api.GET_INSTRUCTION, {
					search: this.query.search,
					deviceCategory: this.query.deviceCategory == i18n.global.t('route.All') ? null : this.query.deviceCategory,
					typeNum: this.query.typeNum == i18n.global.t('route.All') ? null : this.query.typeNum,
					pageNum: this.query.pageNum,
					pageSize: this.query.pageSize
				}, data => {
					this.instructionList = data.data.instructionList;
					this.query.total = data.data.total;
				});
			},
			pdfDetailClick(item) {
				window.open('http://47.114.109.247:8080/pdf-view/web/viewer.html?file=' + encodeURIComponent(JSON.parse(
					item.url)[0]));
			},
			videoDetailClick(item) {
				this.$router.push({
					name: "video-doc",
					params: {
						videoUrl: JSON.parse(item.url)[0]
					}
				}); //页面跳转
			},
			searchClick() {
				this.query.typeNum = i18n.global.t('route.All');
				this.query.deviceCategory = i18n.global.t('route.All');
				this.query.pageNum = 1;
				this.getInstruction();
			},
			handlePageChange(page) {
				this.query.pageNum = page;
				this.getInstruction();
			},

		}
	};
</script>



<style lang="scss" scoped>
	.help-doc {
		color: #444444;
		font-size: 18px;
		padding-right: 20px;
		height: calc(100vh - 100px);
		// overflow: scroll;
		scrollbar-width: none;
		/* firefox */
		-ms-overflow-style: none;
		/* IE 10+ */
		overflow-x: hidden;
		overflow-y: auto;

		>div:nth-of-type(1) {
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-top: 20px;
			background-color: #ffffff;
			padding: 20px;
			border-radius: 5px;

			>label:nth-of-type(1) {
				font-weight: 600;
			}

			>div:nth-of-type(1) {
				width: 1px;
				background-color: #cccccc;
				height: 15px;
				margin: 0px 20px;
			}

			>button:nth-of-type(1) {
				background-image: url(../../assets/img/customer-1.png);
				background-repeat: no-repeat;
				background-size: 100% 100%;
				padding: 5px 10px;
				border: 0px;
				display: flex;
				color: #ffffff;
				flex-direction: row;
				align-items: center;
				font-weight: 800;

				>img {
					margin-right: 7px;
					width: 15px;
					height: 15px;
					content: url(../../assets/img/customer-2.png);
				}
			}
		}

		>div:nth-of-type(2) {
			display: flex;
			flex-direction: column;
			margin-top: 20px;
			background-color: #ffffff;
			padding: 20px;
			border-radius: 5px;


			>div:nth-of-type(1) {
				display: flex;
				flex-direction: row;
				align-items: center;

				.div-handle-right {
					flex: 1;
					flex-direction: row-reverse;
					text-align: right;
					display: flex;
					align-items: center;

					>input:nth-of-type(1) {
						border: 1px solid #eeeeee;
						font-size: 15px;
						width: 200px;
						padding: 5px 8px;
						outline: none;
					}

					>button {
						color: #A866FF;
						margin-left: 10px;
						padding: 4px 20px;
					}
				}
			}

			.table {
				margin-top: 20px;
			}

		}

		.select {
			width: 120px;
			margin-top: 10px;
		}

		.echart {
			height: 150px;
			width: 100%;
		}

		.input {
			width: 250px;
		}


	}
</style>
